/**
 * Created by liuhuaibin on 2018/2/4.
 */
// $(document).ready(function() {
(function () {
    var responseBody = $.ajax({
        url:"/v1/categories",
        method:"GET",
        async:false
        /*data:{"type":type}*/
    });
    var bizData = responseBody.responseJSON;
    console.log(bizData,'!!!!!');
    var pid0 = [],pid1 = [];
    for(var i = 0; i < bizData.length; i ++ ){
        if(bizData[i].pid == 0){
            pid0.push(bizData[i]);
        }else{
            pid1.push(bizData[i]);
        }
    }
    console.log(pid0,'pid0!');
    console.log(pid1,'pid1!');
    var dropdown_ul = document.getElementById('dropdown-ul');
    for(var j = 0; j < pid0.length; j ++){
        var a_el = document.createElement('a');
        a_el.innerHTML = '' + pid0[j].name + '    >';
        var ul_el = document.createElement('ul');
        ul_el.setAttribute('class','dropdown-menu multi third-nav');

        for(var k = 0; k < pid1.length; k ++){
            if(pid1[k].pid == pid0[j].id){
                /* <li> <a> NAME </a> </li>*/
                var in_a_el = document.createElement('a');
                in_a_el.setAttribute('href','search.html?ptype='+pid1[k].id);
                in_a_el.innerHTML = '' + pid1[k].name;

                var in_li_el = document.createElement('li');
                in_li_el.appendChild(in_a_el);

                ul_el.appendChild(in_li_el)
            }
        }
        var li_el = document.createElement('li');
        li_el.appendChild(a_el);
        li_el.appendChild(ul_el);

        dropdown_ul.appendChild(li_el);
    }
})();
function loadUserName(the_token) {
    var responseBody = $.ajax({
        url:"/v1/usersession",
        method:"GET",
        async:false,
        headers:{t:the_token}
    });
    var uidstr = responseBody.responseText;
    //console.log('uidstr',responseBody);
    if(uidstr != '-1' && uidstr != 'undefined'){
        var auc = document.getElementById('a_usercenter');
        auc.setAttribute('href',auc.getAttribute('href')+'&u='+uidstr);
        document.getElementById('usercenter').style.display='inline-block';
        document.getElementById('login').style.display='none';
        document.getElementById('register').style.display='none';
    }
}
// });